<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>调试页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        .debug-info {
            background: #f0f0f0;
            padding: 10px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        .error {
            background: #ffebee;
            color: #c62828;
        }
        .success {
            background: #e8f5e9;
            color: #2e7d32;
        }
        button {
            padding: 10px 20px;
            margin: 10px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <h1>调试页面</h1>
    
    <div class="debug-info" id="debugInfo">
        <p>页面加载时间: <span id="loadTime"></span></p>
        <p>当前URL: <span id="currentUrl"></span></p>
    </div>
    
    <button id="testApiBtn">测试API请求</button>
    <button id="testAlertBtn">测试Alert弹窗</button>
    
    <div id="apiResult" class="debug-info" style="display: none;">
        <h3>API请求结果:</h3>
        <pre id="apiResultContent"></pre>
    </div>

    <script>
        // 页面加载时显示调试信息
        window.onload = function() {
            document.getElementById('loadTime').textContent = new Date().toLocaleString();
            document.getElementById('currentUrl').textContent = window.location.href;
            
            // 显示一个全屏的红色调试弹窗
            const debugDiv = document.createElement('div');
            debugDiv.style.cssText = `
                position: fixed;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: rgba(255, 0, 0, 0.8);
                color: white;
                z-index: 99999;
                display: flex;
                justify-content: center;
                align-items: center;
                font-size: 24px;
                flex-direction: column;
            `;
            debugDiv.innerHTML = `
                <div>调试页面已加载</div>
                <button style="margin-top: 20px; padding: 10px 20px; font-size: 18px;" onclick="this.parentElement.remove()">关闭</button>
            `;
            document.body.appendChild(debugDiv);
            
            // 同时使用alert
            alert('调试页面已加载 - ' + new Date().toLocaleString());
        };
        
        // 测试API请求
        document.getElementById('testApiBtn').addEventListener('click', async () => {
            const resultDiv = document.getElementById('apiResult');
            const resultContent = document.getElementById('apiResultContent');
            const debugInfo = document.getElementById('debugInfo');
            
            debugInfo.innerHTML += '<p>开始测试API请求...</p>';
            
            try {
                const sessionId = '765fc24e-7908-43ac-a934-0e5ae1105f10';
                const response = await fetch(`http://localhost:8000/v1/sessions/${sessionId}/messages`);
                
                resultDiv.style.display = 'block';
                resultContent.textContent = `状态: ${response.status}\n状态文本: ${response.statusText}\n`;
                
                if (response.ok) {
                    const data = await response.json();
                    resultContent.textContent += `响应数据: ${JSON.stringify(data, null, 2)}`;
                    debugInfo.innerHTML += `<p class="success">API请求成功: ${response.status}</p>`;
                } else {
                    debugInfo.innerHTML += `<p class="error">API请求失败: ${response.status} ${response.statusText}</p>`;
                }
            } catch (error) {
                debugInfo.innerHTML += `<p class="error">API请求错误: ${error.message}</p>`;
                resultDiv.style.display = 'block';
                resultContent.textContent = `错误: ${error.message}`;
            }
        });
        
        // 测试Alert弹窗
        document.getElementById('testAlertBtn').addEventListener('click', () => {
            alert('这是一个测试弹窗 - ' + new Date().toLocaleString());
        });
    </script>
</body>
</html>